package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.Salary;
import cn.wolfcode.crm.query.impl.SalaryQuery;
import cn.wolfcode.crm.service.ISalaryService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("salary")
public class SalaryController {
    @Autowired
    private ISalaryService service;

    @RequestMapping("view")
    public String view(){
        return "salary";
    }
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(SalaryQuery qo){
        PageResult query = service.query(qo);
        System.out.println(query.getRows());
        return service.query(qo);
    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Salary salary){
        try {
                service.saveOrUpdate(salary);
        }catch (Exception e){
            e.printStackTrace();
            return new JSONResult(false,"创建失败哦");
        }
        return new JSONResult();
    }@RequestMapping("exportXls")
    public void exportXls(HttpServletResponse response) throws IOException {
        service.exportXls(response);
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(long id){
        try {
            service.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            return new JSONResult(false,"删除失败");
        }
        return new JSONResult();
    }
}
